/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package YottaTron.Actions;

import YottaTron.Runner;
import YottaTron.Sprites.PlayerSprite;
import YottaTron.Sprites.Sprite;
import org.lwjgl.util.Timer;

/**
 *
 * @author Cenda
 */
public class ReverseAction extends Action {
float totalTime = 0;
    public ReverseAction(Sprite s, float startingTime, Runner r) {
        sprite = s;
        this.startingTime = startingTime;
        this.r = r;
        iterations = 0;
        type = REVERSE_ACTION;
    saveToHistory = true;
        //System.out.println(" zrychluji na "  + rychlost);
        PlayerSprite player = ((PlayerSprite) s);
        if (player.controllable) {
            player.addLastAction(this);
        }
    }

    public boolean nextStep(float deltaTime){

        if (finished) {
           
            totalTime += deltaTime;
            sprite.setSpeed(sprite.getSpeed() - sprite.getAcceleration() * deltaTime);
            sprite.variableChanged = true;
            return false;
        }
        
        if(sprite.getSpeed()>-sprite.getMaxSpeed()){
        if(iterations==0){
            
//            float deltaTime = currentTime - startingTime;
//        sprite.setSpeed(sprite.getSpeed()-sprite.getAcceleration()*deltaTime);
        }else{
            
        sprite.setSpeed(sprite.getSpeed()-sprite.getAcceleration()*deltaTime);
        sprite.variableChanged = true;
        }
         }
        totalTime += deltaTime;
        iterations++;
        //System.out.println("akceleruji");
        return true;

    }

    

}
